#include using std::cin; using std::cout; using std::endl; const int MAX_STRING_LENGTH = 100; //'a' vs "a" int stringLength(char s[]) { int result = 0; while(s[result]!= '\0') { result++; } return result; } void stringCopy(char destination[], char source[]) { int i = 0; do { destination[i] = source[i]; i++; } while(source[i-1] != '\0'); } //bool sameStrings(char s1[], char s2[]) //{ // //return true if they have the same chars in the arrays // //} // bool sameStringsCaseInsensitive(char s1[], char s2[]) { bool stringsAreEqual = true; int s1Length = stringLength(s1); int s2Length = stringLength(s2); if( s1Length != s2Length ) { stringsAreEqual = false; } else { for(int i = 0; i < s1Length && stringsAreEqual;i++) { if(toupper(s1[i]) != toupper(s2[i])) { stringsAreEqual = false; } } } return stringsAreEqual; } // void stringAppend(char destination[], char source[]) { //copy all of the chars from source to the end of the destination stringCopy(destination + stringLength(destination),source); } // //int indexOfChar(char s[], char c) //{ // //return the first index in string s where the char c is found // //return -1 if it is not found //} void main() { if(sameStringsCaseInsensitive("Apple", "Apple")) cout << "Same 1" << endl; if(sameStringsCaseInsensitive("APPLE", "Apple")) cout << "Same 2" << endl; if(sameStringsCaseInsensitive("Appl", "Apple")) cout << "Same 3" << endl; if(sameStringsCaseInsensitive("Apple", "Apples")) cout << "Same 4" << endl; if(sameStringsCaseInsensitive("Apple ", " Apple")) cout << "Same 5" << endl; if(sameStringsCaseInsensitive("Apples", "Apple")) cout << "Same 6" << endl; }